//
//  KnobRotationGestureRecognizer.m
//  SKPAD
//
//  Created by admin@amonline.com.cn on 15/5/8.
//  Copyright (c) 2015年 amo. All rights reserved.
//

#import "KnobRotationGestureRecognizer.h"

@implementation KnobRotationGestureRecognizer

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    [self updateTouchAngleWithTouches:touches];
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesMoved:touches withEvent:event];
    [self updateTouchAngleWithTouches:touches];
}

//获取触摸点集合
-(void)updateTouchAngleWithTouches:(NSSet *)touches
{
    UITouch * touch = [touches anyObject];
    //触摸点坐标转化为添加了该手势的试图坐标系坐标
    CGPoint touchPoint = [touch locationInView:self.view];
    self.touchAngle = [self calculateAngleToPoint:touchPoint];
}

-(CGFloat) calculateAngleToPoint:(CGPoint)point
{
    CGPoint centerOffset = CGPointMake(point.x - CGRectGetMidX(self.view.bounds), point.y - CGRectGetMidY(self.view.bounds));
    return atan2(centerOffset.y, centerOffset.x);
}

-(id) initWithTarget:(id)target action:(SEL)action
{
    self = [super initWithTarget:target action:action];
    if(self)
    {
        //单手指触摸
        self.maximumNumberOfTouches = 1;
        self.minimumNumberOfTouches = 1;
    }
    return self;
}
@end